package exam.yingjiao.S1;

import util.ListUtil;

public class Main {

    public static int n;

    public static void main(String[] args) {
        int[] a = ListUtil.parseIntArray("[1,3,6,9]");
        System.out.println(new Main().numsOfMethods(a));
    }

    public long numsOfMethods(int[] a) {
        long res = 0, num3 = 0, num9 = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i] % 9 == 0)
                num9++;
            else if (a[i] % 3 == 0)
                num3++;
        }
        res += (a.length - num9) * num9;
        res += ((num9 * (num9-1) / 2));
        res += ((num3 * (num3-1) / 2));
        return res;
    }
}